package com.xyoto.community.task;

import com.xyoto.community.constant.moduleConstant;
import com.xyoto.community.entity.main.HotTopic;
import com.xyoto.community.utils.RedisCommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class HotTopicRedisImpl {

    @Autowired
    private RedisCommonUtils redisCommonUtils;

    /**
     * 将热门话题存入redis
     * @param hotTopics
     */
    public void saveHotTopic(List<HotTopic> hotTopics) {

        for (HotTopic hotTopic : hotTopics) {
            redisCommonUtils.zSet(moduleConstant.HOT_TOPIC,hotTopic.getTopicId(),hotTopic.getCurrentHot().doubleValue());
        }
        log.info("添加后的热门话题为" + redisCommonUtils.rangeByZSetAll(moduleConstant.HOT_TOPIC));

    }

}
